<template>
  <el-container class="homeContainer">
    <!-- 头部 -->
    <el-header>
      <div class="backStageName">
        <img
          class="titleBarImg"
          :src="require('@/assets/titleBar.png')"
          alt="titleBar"
        />
        <span class="titleName">这是一个后台管理系统</span>
      </div>
      <el-button @click="exitLogin">退出</el-button>
    </el-header>
    <!-- 侧边栏 -->
    <el-container>
      <el-aside :width="iscollapse ? '61px' : '200px'">
        <!-- 切换按钮 -->
        <div class="toggle-button" @click="iscollapseBtn()">|||</div>
        <!-- 侧边栏菜单区域 -->
        <el-menu
          class="el-menu-vertical-demo"
          background-color="#263b58"
          text-color="#fff"
          active-text-color="#ffd04b"
          :unique-opened="true"
          :default-active="defaultActive"
          :collapse="iscollapse"
          :collapse-transition="false"
          :router="true"
        >
          <el-submenu
            v-for="item in menusList"
            :key="item.id"
            :index="'/' + item.path"
          >
            <template slot="title">
              <i :class="iconList[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              v-for="sonitem in item.children"
              :key="sonitem.id"
              :index="'/' + sonitem.path"
            >
              <template>
                <i :class="iconList[sonitem.id]"></i>
                <span>{{ sonitem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-container>
        <el-main>
          <breadcrumb-plug></breadcrumb-plug>
            <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
import { getMenusApi } from '@/Utils/Api/getUserInfoApi'
import BreadcrumbPlug from '@/components/Breadcumb/BreadcumbPlug.vue'
export default {
  name: 'HomeView',
  data () {
    return {
      menusList: [],
      iconList: {
        125: 'el-icon-s-custom',
        110: 'el-icon-wallet',
        103: 'el-icon-lock',
        111: 'el-icon-place',
        112: 'el-icon-set-up',
        101: 'el-icon-shopping-bag-2',
        104: 'el-icon-shopping-cart-full',
        115: 'el-icon-sell',
        121: 'el-icon-shopping-cart-full',
        102: 'el-icon-notebook-1',
        107: 'el-icon-notebook-2',
        145: 'el-icon-data-line',
        146: 'el-icon-pie-chart'
      },
      iscollapse: false
    }
  },

  components: {
    BreadcrumbPlug
  },
  created () {
    this.getMenusList()
  },
  mounted () {},
  methods: {
    exitLogin () {
      window.localStorage.clear()
      this.$router.push('./login')
    },
    async getMenusList () {
      const { data: res } = await getMenusApi()
      this.menusList = res.data
    },
    iscollapseBtn () {
      this.iscollapse = !this.iscollapse
    }
  },
  computed: {
    menusItemList () {
      const nowPath = this.$route.path
      return this.menusList.filter((item) => item.path === '/' + nowPath)
    },
    defaultActive () {
      if (this.$route.path === '/goods/addGoods') {
        return '/goods'
      }
      return this.$route.path
    }
  },
  watch: {}
}
</script>

<style lang="less" scoped>
.homeContainer {
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0;
  background-color: #263b58;
  color: #333;
  .backStageName {
    display: flex;
    align-items: center;
    .titleBarImg {
      width: 60px;
      height: 60px;
      border-radius: 50%;
    }
    .titleName {
      margin-left: 12px;
      font-size: 18px;
      color: #e9eef3;
      user-select: none;
    }
  }
}
.el-aside {
  background-color: #263b58;
  .el-menu {
    border-right: none;
    user-select: none;
  }
}
.el-main {
  background-color: #e9eef3;
  color: #333;
}
.toggle-button {
  color: #fff;
  background-color: #263b58;
  font-size: 12px;
  line-height: 24px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
  user-select: none;
}
</style>
